package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Fruit;
import com.ruoyi.system.service.IFruitService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 水果列表Controller
 * 
 * @author ruoyi
 * @date 2023-11-11
 */
@RestController
@RequestMapping("/system/fruit")
public class FruitController extends BaseController
{
    @Autowired
    private IFruitService fruitService;

    /**
     * 查询水果列表列表
     */
    @PreAuthorize("@ss.hasPermi('system:fruit:list')")
    @GetMapping("/list")
    public TableDataInfo list(Fruit fruit)
    {
        startPage();
        List<Fruit> list = fruitService.selectFruitList(fruit);
        return getDataTable(list);
    }
    /**
     * 测试
     */
    @PreAuthorize("@ss.hasPermi('system:fruit:permtest')")

    @GetMapping("/permTest")
    public AjaxResult permTest()
    {
        return AjaxResult.success("permTest success");
    }
    /**
     * 导出水果列表列表
     */
    @PreAuthorize("@ss.hasPermi('system:fruit:export')")
    @Log(title = "水果列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Fruit fruit)
    {
        List<Fruit> list = fruitService.selectFruitList(fruit);
        ExcelUtil<Fruit> util = new ExcelUtil<Fruit>(Fruit.class);
        util.exportExcel(response, list, "水果列表数据");
    }

    /**
     * 获取水果列表详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:fruit:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(fruitService.selectFruitById(id));
    }

    /**
     * 新增水果列表
     */
    @PreAuthorize("@ss.hasPermi('system:fruit:add')")
    @Log(title = "水果列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody Fruit fruit)
    {
        return toAjax(fruitService.insertFruit(fruit));
    }

    /**
     * 修改水果列表
     */
    @PreAuthorize("@ss.hasPermi('system:fruit:edit')")
    @Log(title = "水果列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Fruit fruit)
    {
        return toAjax(fruitService.updateFruit(fruit));
    }

    /**
     * 删除水果列表
     */
    @PreAuthorize("@ss.hasPermi('system:fruit:remove')")
    @Log(title = "水果列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(fruitService.deleteFruitByIds(ids));
    }
}
